/**
 * 
 */

package com.kugou.game.sdk.ui.dialog;

import com.kugou.game.sdk.api.common.User;
import com.kugou.game.sdk.core.PayManager;
import com.kugou.game.sdk.core.UserManager;
import com.kugou.game.sdk.persistence.preference.PrefUtil;
import com.kugou.game.sdk.utils.Rx;

import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 描述:支付密码设置成功对话框
 *
 * @author jerryliu
 * @since 2015年8月25日 下午5:36:38
 */
public class SetPayPsdSuccessDialog extends AbsDialog {
    private TextView mAccount;

    private ImageView mImage1, mImage2, mImage3, mImage4;

    private CheckBox box;

    private User user;

    public SetPayPsdSuccessDialog(Activity activity) {
        super(activity);
    }

    @Override
    protected View createContentView() {
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(Rx.layout.kg_view_set_pay_psd_success, null);
        mAccount = (TextView) view.findViewById(Rx.id.kg_security_account);
        mImage1 = (ImageView) view.findViewById(Rx.id.kg_security_img_1);
        mImage2 = (ImageView) view.findViewById(Rx.id.kg_security_img_2);
        mImage3 = (ImageView) view.findViewById(Rx.id.kg_security_img_3);
        mImage4 = (ImageView) view.findViewById(Rx.id.kg_security_img_4);
        box = (CheckBox) view.findViewById(Rx.id.kg_iv_check_state);

        return view;
    }

    @Override
    public void onContentChanged() {
        super.onContentChanged();
        user = UserManager.getInstance().getCurrentUserInternal();
        mAccount.setText(Html.fromHtml("您当前账号安全评分:<font color=\"#f32525\">"
                + user.getSecurityScore() + "</font>分"));
        refreshSecurityState();
        setCancelClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (box.isChecked()) {// 勾选不再弹窗提示
                    PrefUtil.setPaySecurityTipNeedShow(getContext(), user.getOpenId(), false);
                    PayManager.setPaySecurityTipNeedShow(user.getOpenId());
                }
                dismiss();
            }
        });
    }

    private void refreshSecurityState() {
        // 安全图标
        if (!TextUtils.isEmpty(user.getBindPhoneNum())) {
            mImage1.setImageResource(Rx.drawable.kg_security_phone_binded);
        } else {
            mImage1.setImageResource(Rx.drawable.kg_security_phone_default);
        }
        if (!TextUtils.isEmpty(user.getSecurityEmail())) {
            mImage2.setImageResource(Rx.drawable.kg_security_email_binded);
        } else {
            mImage2.setImageResource(Rx.drawable.kg_security_email_default);
        }
        if (user.getSecurityQuestionId() != 255) {
            mImage3.setImageResource(Rx.drawable.kg_security_question_set);
        } else {
            mImage3.setImageResource(Rx.drawable.kg_security_question_default);
        }
        if (user.isSetIdentity()) {
            mImage4.setImageResource(Rx.drawable.kg_security_identity_binded);
        } else {
            mImage4.setImageResource(Rx.drawable.kg_security_identity_default);
        }
    }
}
